<template>
	<u-popup :show="show" @close="close" :safeAreaInsetBottom="false" :closeOnClickOverlay="false" zIndex="99999"
		bgColor="transparent" mode="center">
		<view class="box" @click="openLink">
			<image v-if="adv" class="pic" :src="adv.imgUrl" mode=""></image>
			<view class="close_btn">
				<text>{{ num }}s后自动关闭</text>
				<view @click.stop="close">
					<image class="close" src="https://yzxk.oss-cn-hangzhou.aliyuncs.com/images/common/start_close.png" mode=""></image>
				</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import {
		getUserData
	} from '@/apis/apis.js';
	export default {
		name: 'openAdv',
		props: {
			show: {
				type: Boolean,
				default: false
			},
			adv: {
				type: Object,
				default: null
			}
		},
		data() {
			return {
				num: 0,
				timer: null,
				vipEndDay: 0,
			};
		},
		mounted() {
			const token = uni.getStorageSync('token');
			//判断是否会员
			if(token){
			getUserData().then(res => {
				console.log(res, "获取")
				this.vipEndDay = res.data.vipEndDay
			});
			}
			uni.hideTabBar()
			this.num = this.adv.autoOffTime
			this.timer = setInterval(() => {
				this.num--;
				if (this.num == 0) {
					this.close()
				}
			}, 1000);
		},
		methods: {
			close() {
				clearInterval(this.timer);
				this.timer = null
				this.num = 0
				uni.showTabBar()
				this.$emit('close')
			},
			openLink() {
				this.close()
				console.log(this.adv)
				// 0不跳转 1单独详情页  2内页面 3外链
				if (this.adv.linkType == 0) return
				if (this.vipEndDay>0 && this.adv.linkStatus ==0) return
				if (this.adv.linkType == 1) {
					uni.navigateTo({
						url: `./banner/banner?content=${this.adv.content}`
					});
				}
				if (this.adv.linkType == 2) {
					uni.navigateTo({
						url: this.adv.linkUrl
					})
				}
				if (this.adv.linkType == 3) {
					const url = encodeURIComponent('http://' + this.adv.linkUrl);
					uni.navigateTo({
						url: `/pages/outsideLink/outsideLink?url=${url}`
					})
				}
				// const url = encodeURIComponent('http://' + this.adv.linkUrl);
				// uni.navigateTo({
				// 	url: `/pages/outsideLink/outsideLink?url=${url}`
				// });
			}
		}
	};
</script>

<style lang="scss" scoped>
	.box {
		position: relative;
		width: 640rpx;
		height: 960rpx;
		border-radius: 20rpx;
		overflow: hidden;

		.pic {
			display: block;
			width: 100%;
			height: 100%;
		}

		.close_btn {
			position: absolute;
			top: 20rpx;
			right: 26rpx;
			font-size: 26rpx;
			color: #ffffff;
			display: flex;
			align-items: center;

			&>text {
				margin-right: 15rpx;
			}

			.close {
				display: block;
				width: 22rpx;
				height: 22rpx;
			}
		}
	}
</style>
